package com.david.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Description: PaymentController
 * @Author: wangwei
 * @CreateDate: 2022/1/13 11:04
 */
@RestController
public class PaymentController {


    @Value("${server.port}")
    private  String serverPort;

    @GetMapping("/payment/consul")
    @HystrixCommand(fallbackMethod = "paymentConsulHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String paymentConsul(){
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        int i=10/0;
        return "springcloud with consul:"+serverPort+"  >> "+ UUID.randomUUID().toString();
    }

    public String paymentConsulHandler(){

        return "paymentConsulHandler with consul:"+serverPort+"  >> "+ UUID.randomUUID().toString();
    }
}

